//
//  LoginBiometricView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/2/2.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

public protocol LoginBiometricViewDelegate {
    
    func clickBiometric()
    func clickSwitchBtn()
}

class LoginBiometricView: UIView {
    
    // 快捷图片
    private lazy var biometricPic = UIImageView(image: UIImage(named: "login1"))
    
    public var delegate:LoginBiometricViewDelegate?
    
    public var resetBimoetricPic:Int? {
        didSet {
            biometricPic.image = UIImage(named: "login2")
        }
    }
    
    override func layoutSubviews() {
        // 头像
        let headerPic = UIImageView(image: UIImage(named: "main_avatar_97x97"))
        headerPic.frame.origin = CGPoint(x: (frame.width - headerPic.bounds.width) * 0.5, y: frame.height * 0.15)
        addSubview(headerPic)
        // 获取手机号
        let mobile = UserDefaults.standard.value(forKey: SP_MOBILE) as? String
        // 手机号文本
        let mobieLabel = UILabel(title: mobile!, color: COLOR_NICE, size: 20,align: .center)
        mobieLabel.frame = CGRect(x: 0, y: headerPic.frame.maxY + MARGIN, width: frame.width, height: MARGIN20)
        addSubview(mobieLabel)
        // 快捷图片
        let biometriicY = (frame.height - biometricPic.bounds.height) * 0.5
        biometricPic.frame.origin = CGPoint(x: (frame.width - MARGIN60) * 0.5, y: biometriicY)
        biometricPic.isUserInteractionEnabled = true
        addSubview(biometricPic)
        biometricPic.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickBiometric)))
        // 提示文本
        let clickLabel = UILabel(title: "点击进行解锁", color: COLOR_LOGIN, size: 14,align: .center)
        clickLabel.frame = CGRect(x: 0, y: biometricPic.frame.maxY + MARGIN, width: frame.width, height: MARGIN20)
        addSubview(clickLabel)
        // 更多文本
        let moreLabel = UILabel(title: "切换登录方式", color: UIColor.darkGray, size: 14,align: .right)
        let moreX = frame.width - MARGIN100 - MARGIN
        moreLabel.frame = CGRect(x: moreX, y: frame.height - MARGIN40, width: MARGIN100, height: MARGIN30)
        addSubview(moreLabel)
        moreLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickSwitchBtn)))
    }
    
    @objc func clickBiometric() -> Void {
        delegate?.clickBiometric()
    }
    
    @objc func clickSwitchBtn() -> Void {
        delegate?.clickSwitchBtn()
    }
}
